<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Table</title>
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/table.css"/>
    <style type="text/css">
        .searcheBottom{margin-bottom: 10px;}
    </style>
</head>

<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote">
        <div class="layui-inline searcheBottom">
            <div class="layui-inline" style="margin-right: 30px;">
                <h3><b>当前交易所：${exchangeName!}</b></h3>
                <input id="exchangeId" name="exchangeId" class="layui-input" style="display: none" value="${id!}"/>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            时间维度名称：
            <div class="layui-inline">
                <input id="dimensionName" class="layui-input" name="dimensionName" autocomplete="off" placeholder="时间维度名称"/>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            状态：
            <div class="layui-inline">
                <select  id="enableFlag" name="enableFlag" class="layui-input" style="padding: 0px 20px;">
                    <option value="">全部</option>
                    <option value="1">启用</option>
                    <option value="0">停用</option>
                </select>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            <a class="layui-btn" data-type="reload" id="search">搜索</a>
            <a class="layui-btn layui-btn-primary" id="reset">重置</a>
        </div>
        <div class="layui-inline searcheBottom">
            <div class="layui-inline" >
                &nbsp;
                <a data-opt="add" href="/manage/latmdle/addelat?id=${id!}&exchangeName=${exchangeName!}" class="layui-btn">
                    <i class="layui-icon">&#xe608;</i>添加时间维度</a>
                <a href="/manage/exchange/exchangeInfoList" class="layui-btn layui-btn-primary">返回</a>
            </div>
        </div>
    </blockquote>
    <span style="font-size: 16px;"><b>时间维度列表</b></span>
    <table class="layui-hide" id="elatTable" lay-filter="tableFilter"></table>
</div>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script>
    layui.use(['form', 'laydate','table','laydate','util'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,//表格
            laydate = layui.laydate,//日期
            util = layui.util;//工具类

        var id = parseInt(${id!});

        pageInit();

        //执行一个 table 实例
        function pageInit(){
            table.render({
                elem: '#elatTable'
                ,url:'/manage/latmdle/sellatmidele'
                ,where: {
                    exchangeId: id
                }
                ,method: 'post'
                ,cols: [[
                    {field:'id', title: 'ID',width:150, sort: true}
                    ,{field:'dimensionName', title: '时间维度名称',align:'center'}
                    ,{field:'enableFlag', title: '状态',align:'center',
                        templet: function(d){
                            if(d.enableFlag==true){
                                return '<div class="layui-btn layui-bg-green layui-btn-xs">启用</div>'
                            } else if(d.enableFlag==false){
                                return '<div class="layui-btn layui-bg-gray layui-btn-xs">停用</div>'
                            }
                        }
                    },
                    {field:'createTime', title: '添加时间',sort: true,align:'center',
                        templet: function(d){
                            if(d.createTime !=null){
                                return util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss');
                            }else{
                                return '';
                            }
                        }
                    },{title:"操作", align:'center',templet: function(d){
                            var tool="";
                        if(d.enableFlag==true){
                            tool+= '<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="edit">停用</a>';
                        }else if(d.enableFlag==false){
                            tool+= '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">启用</a>';
                        }
                        return tool += '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>';
                    }}
                ]],
                limits:[10,15,20,25,30],
                limit:10,
                page: true
            });
        }

        //表格重载
        var active = {
            reload: function () {
                var dimensionName = $('#dimensionName');
                var exchangeId = $('#exchangeId');
                var enableFlag = $('#enableFlag');
                table.reload('elatTable', {
                    where: {
                        dimensionName: dimensionName.val(),
                        exchangeId:exchangeId.val(),
                        enableFlag:enableFlag.val(),
                    }
                });
            }
        };

        //将搜索框的值随请求传到后台
        $('#search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $("input").keydown(function (e) {
            if(e.keyCode == 13){
                $('#search').click();
            }
        });
        //重置
        $("#reset").on("click",function(){
            dimensionName.value = '';
            enableFlag.value = '';
        });

        //表格监听
        table.on('tool(tableFilter)', function(obj){
            var data = obj.data;
            if (obj.event == "edit") {
                $.ajax({
                    url:"/manage/latmdle/enablelat",
                    type:"post",
                    dataType:"json",
                    data:{"id":data.id,"enableFlag":data.enableFlag},
                    success:function(count){
                        pageInit();
                    }
                })
            }else if(obj.event == "del"){
                $.ajax({
                    url:"/manage/latmdle/deleteLelat",
                    type:"post",
                    dataType:"json",
                    data:{"id":data.id},
                    success:function(count){
                        pageInit();
                    }
                })
            }
        });

    });
</script>
</body>

</html>